package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import po.Product;
import po.Role;
import service.RoleService;
import utils.ResUtils;

import java.util.List;


@Controller
public class RoleController {
    @Autowired
    private RoleService roleService;

    // 根据 id 获取管理员权限
    @GetMapping("/roles/{id}")
    @ResponseBody
    public Role userOfId(@PathVariable("id") Integer id) {

        Role role = roleService.roleOfId(id);

        return role;
    }

    @GetMapping("/roles")
    @ResponseBody
    public Object AllRoles() {

        List<Role> res = this.roleService.allRole();

        if ( res != null) {
            return ResUtils.Success(1,"查询成功",res);
        } else {
            return ResUtils.Fail(0,"没有数据");
        }
    }
}
